package com.chj.design.sk;

public class Code19_State {
	public interface State {
		void handle();
	}

	/**
	 * 空闲状态
	 */
	public static class FreeState implements State {

		@Override
		public void handle() {
			System.out.println("房间空闲！没人住！");
		}
	}

	/**
	 * 已预订状态
	 */
	public static class BookedState implements State {

		@Override
		public void handle() {
			System.out.println("房间已预订！别人不能定！");
		}
	}

	/**
	 * 已入住状态
	 */
	public class CheckedInState implements State {

		@Override
		public void handle() {
			System.out.println("房间已入住！别人不能入住！");
		}
	}

	/**
	 * 房间对象
	 */
	public static class HomeContext {
		// 如果是银行系统，这个Context类就是账号。根据金额不同，切换不同的状态！

		private State state;

		public void setState(State s) {
			System.out.println("修改状态！");
			state = s;
			state.handle();
		}
	}

	public static void main(String[] args) {
		HomeContext ctx = new HomeContext();

		ctx.setState(new FreeState());

		ctx.setState(new BookedState());
	}

}
